{include file="public/layout" /}

<body class="bodystyle" style="overflow-x: hidden;padding: 0;min-width: 674px;background: #fff;">
<style type="text/css">
    .ncap-form-default dd.opt { width: 79%; }
    .select-express {border: 1px solid red !important; color: red !important;}
</style>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="margin: 0 auto;">
    <div class="flexigrid">
        <form class="form-horizontal" id="postForm">
            <input type="hidden" name="order_id" value="{$orderData.order_id}">
            <input type="hidden" name="users_id" value="{$orderData.users_id}">
            <input type="hidden" name="order_code" value="{$orderData.order_code}">
            <input type="hidden" name="order_status" value="{$orderData.order_status}">
            <input type="hidden" name="actual_price" value="{$orderData.actual_price}">
            <input type="hidden" name="actual_points" value="{$orderData.actual_points}">
            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit">
                        <label>订单总额</label>
                    </dt>
                    <dd class="opt">
                        ￥{$orderData.order_total_amount}
                    </dd>
                </dl>

                {notempty name="$orderData.coupon_id"}
                <dl class="row">
                    <dt class="tit">
                        <label>优惠券</label>
                    </dt>
                    <dd class="opt">
                        -￥{$orderData.coupon_price}
                    </dd>
                </dl>
                {/notempty}
                {notempty name="$orderData.shipping_fee"}
                <dl class="row">
                    <dt class="tit">
                        <label>运费</label>
                    </dt>
                    <dd class="opt">
                        ￥{$orderData.shipping_fee}
                    </dd>
                </dl>
                {/notempty}
                <dl class="row">
                    <dt class="tit">
                        <label>实付总额</label>
                    </dt>
                    <dd class="opt">
                        ￥{$orderData.order_amount}
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label>退款金额</label>
                    </dt>
                    <dd class="opt">
                        ￥{$orderData.actual_price}
                        <p class="notic2">退款金额 = 订单总额 - 优惠券金额 - 本单已完成售后商品金额 - 运费</p>
                        <!-- <div class="inpit-word">
                            <input type="text" value="{$orderData.actual_price}" data-price="{$orderData.actual_price}" name="actual_price" id="actual_price" onpaste='this.value=this.value.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/, "$1");' onkeyup='this.value=this.value.replace(/^\D*([0-9]\d*\.?\d{0,2})?.*$/, "$1"); actualPrice(this);' class="no-drop" disabled readonly="readonly">
                            <div class="word">￥</div>
                        </div> -->
                    </dd>
                </dl>

                {notempty name="$orderData.points_shop_order"}
                <dl class="row">
                    <dt class="tit">
                        <label>退还积分</label>
                    </dt>
                    <dd class="opt">
                        {$orderData.actual_points}积分
                        <!-- <div class="inpit-word">
                            <input type="text" value="{$orderData.actual_points}" data-points="{$orderData.actual_points}" name="actual_points" id="actual_points" onpaste='this.value=this.value.replace(/^\D*([0-9]\d*)?.*$/, "$1");' onkeyup='this.value=this.value.replace(/^\D*([0-9]\d*)?.*$/, "$1"); actualPoints(this);' class="no-drop" disabled readonly="readonly">
                            <div class="word">积分</div>
                        </div> -->
                    </dd>
                </dl>
                {/notempty}

                <dl class="row">
                    <dt class="tit"> <label>退款方式</label> </dt>
                    <dd class="opt" style="line-height: 30px;">
                        <label>
                            <input type="radio" name="refund_way" id="refund_way" value="1" {eq name="$orderData.refund_way" value="1"} checked="true" {/eq}>退款到余额{notempty name="$orderData.points_shop_order"}(积分){/notempty}
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="radio" name="refund_way" id="refund_way" value="2" {eq name="$orderData.refund_way" value="2"} checked="true" {/eq}>线下退款
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label title="用户使用微信支付下单才可以选择">
                            <input type="radio" name="refund_way" id="refund_way" value="3" {eq name="$orderData.refund_way" value="3"} checked="true" {/eq} {neq name="$orderData.pay_name" value="wechat"} disabled="true" {/neq}>原路退回(微信)
                        </label>
                        <p class="notic2">商家在操作主动退款完成后，会在客户端生成一条已完成的维权订单。</p>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label>退款说明</label>
                    </dt>
                    <dd class="opt">
                        <textarea rows="5" cols="60" name="refund_remark" style="height: 80px;"></textarea>
                    </dd>
                </dl>
            </div>

            <div class="ncap-form-default">
                <div class="bot" style="padding-bottom: 0px;">
                    <a href="JavaScript:void(0);" onclick="submitOrderActiveRefund();" class="ncap-btn-big ncap-btn-green">确认退款</a>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    // 验证实际退款金额是否超过
    function actualPrice(obj) {
        var value = $(obj).val();
        var price = $(obj).data('price');
        if (parseFloat(value) > parseFloat(price)) {
            $(obj).val(price);
        } else {
            $(obj).val(value);
        }
    }

    // 验证实际退款积分是否超过
    function actualPoints(obj) {
        var value = $(obj).val();
        var price = $(obj).data('points');
        if (parseInt(value) > parseInt(price)) {
            $(obj).val(price);
        } else {
            $(obj).val(value);
        }
    }

    // 表单提交
    function submitOrderActiveRefund() {
        if (!$('#refund_way:checked').val()) {
            showErrorMsg('请选择退款方式');
            return false;
        }
        // var actualPrice = $('#actual_price').val();
        // if (isNaN(actualPrice) || 0 > parseFloat(actualPrice)) {
        //     showErrorMsg('实际退款余额不能小于0');
        //     $('#actual_price').focus();
        //     return false;
        // }
        layer_loading('正在处理');
        $.ajax({
            type: "post",
            url : "{:url('Shop/order_active_refund', ['_ajax'=>1])}",
            data: $('#postForm').serialize(),
            dataType: 'json',
            success: function (res) {
                layer.closeAll();
                if (1 === parseInt(res.code)) {
                    showSuccessMsg(res.msg, 1000, function() {
                        parent.window.location.reload();
                    });
                    if (res.data.email) unifySendEmail(res.data.email);
                    if (res.data.mobile) unifySendMobile(res.data.mobile);
                    if (res.data.weChat) unifySendWeChat(res.data.weChat);
                } else {
                    showErrorAlert(res.msg);
                }
            },
            error:function(e){
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    }
</script> 
